home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00a.txt / 000030_icon-group-sender _Thu Feb 10 16:26:43 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA17405
  4.     for icon-group-addresses; Thu, 10 Feb 2000 16:24:16 -0700 (MST)
  5. Message-Id: <200002102324.QAA17405@baskerville.CS.Arizona.EDU>
  6. Date: Thu, 10 Feb 2000 17:08:23 -0600
  7. From: "Charles Hethcoat" <CHETHCOA@oss.oceaneering.com>
  8. To: <icon-group@optima.CS.Arizona.EDU>
  9. Subject: Dereferencing, updating, and `pseudovariables' in Icon
  10. Content-Disposition: inline
  11. X-Guinevere: 1.0.13 ; Oceaneering Int'l
  12. X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id QAA16732
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15.  
  16. I want to put something like the following code in an application I'm writing.  The two subordinate procedures define something that I call "pseudovariables".  (Anyone remember PL/I?)
  17. ---------------------------------8<-------------------------------------------------
  18. procedure main()
  19.  
  20.     write("pseudovar_1() = ", pseudovar_1())
  21.     pseudovar_1() +:= 1
  22.     write("pseudovar_1() = ", pseudovar_1())
  23.  
  24.     write("pseudovar_2() = ", pseudovar_2())
  25.     pseudovar_2() +:= 2    
  26.     write("pseudovar_2() = ", pseudovar_2())
  27.  
  28.     return
  29. end
  30.  
  31. # pseudovar_1 - return name of a local static variable
  32. procedure pseudovar_1()
  33.     static _pseudovar_1
  34.     initial _pseudovar_1 := 1
  35.     return _pseudovar_1
  36. end
  37.  
  38. # pseudovar_2 - return value of a local static variable
  39. procedure pseudovar_2()
  40.     static _pseudovar_2
  41.     initial _pseudovar_2 := 1
  42.     return ._pseudovar_2    # note the dot!
  43. end
  44. ---------------------------------8<-------------------------------------------------
  45. Question:  Is there any way to retain control in this situation?  I would like to detect the attempt to assign to a read-only variable and tell the user that he can't do that.  I was hoping to be able to do this:
  46.  
  47.     pseudovar_2() +:= 2     | stop("Hey!  Stop that!")
  48.  
  49. But it doesn't `fail'--it just suddenly croaks.  Here is what I get when I run it:
  50.  
  51. pseudovar_1() = 1
  52. pseudovar_1() = 2
  53. pseudovar_2() = 1
  54.  
  55. Run-time error 111
  56. File newpseudo.icn; Line 8
  57. variable expected
  58. offending value: 1
  59. Traceback:
  60.    main()
  61.    {1 := 3} from line 8 in newpseudo.icn
  62.  
  63. Is there any other way to accomplish this end?  It's for a split application:  I write the numerical integration code, and presumably someone else writes code implementing the differential equation describing his problem, and links it to my prewritten integrator, which, I should not forget to add, contains main() and a bunch of predefined global variables beginning with "_".  Some of these must be updated by the user, others must not be.  So I would like to use this technique (or something better, if it exists) to manage the situation.
  64.  
  65. Thanks for your time and interest in advance.
  66.  
  67. Charlie Hethcoat
  68. Oceaneering Space Systems
  69.  
  70.